#!/urs/bin/python
# -*- coding:utf-8 -*-
# 多线程的用法

import urllib2
import threading
import time
import random

def my_function(url,tid):
    while True:
	    res = urllib2.urlopen(url)
	    print tid,res.msg + '|' + url
	    time.sleep(random.randint(1,5))

url = "http://www.baidu.com"
t_count = 20  #变量，线程数为20

for i in range(0,t_count):
    t = threading.Thread(target=my_function,args=(url,i))
    t.start()